package com.sky.controller.user;

import com.sky.Result.PageResult;
import com.sky.Result.Result;
import com.sky.model.dto.ShopPageQueryDTO;
import com.sky.model.dto.UserBehaviorDTO;
import com.sky.service.ShopService;
import com.sky.service.UserBehaviorService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@Slf4j
@RequestMapping("/user/shop")
@CrossOrigin
public class ShopController {
    @Autowired
    ShopService shopService;
    @Autowired
    UserBehaviorService userBehaviorService;

    /**
     * 商品主页信息查询
     * @param shopPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    public Result<PageResult>page(@RequestBody ShopPageQueryDTO shopPageQueryDTO) {
        log.info("商品主页信息查询：{}", shopPageQueryDTO);
        PageResult page = shopService.pageQuery(shopPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 商品收藏
     * @param userBehaviorDTO
     */
    @PostMapping("/star")
public Result collect(@RequestBody UserBehaviorDTO userBehaviorDTO) {
    log.info("商品收藏：{}", userBehaviorDTO);
    userBehaviorService.bookmark(userBehaviorDTO);
    return Result.success();
}

    /**
     * 商品详情（浏览）
     * @param shopPageQueryDTO
     */
    @PostMapping("/views/detail")
        public Result<PageResult>viewsDetail(@RequestBody ShopPageQueryDTO shopPageQueryDTO) {
            log.info("商品浏览记录信息查询：{}", shopPageQueryDTO);
            PageResult page = userBehaviorService.history(shopPageQueryDTO);
            return Result.success(page);
        }

    /**
     * 商品详情（收藏）
     * @param shopPageQueryDTO
     */
    @PostMapping("/stars/detail")
/*    public Result starsDetail(@RequestBody UserBehaviorDTO userBehaviorDTO) {
        log.info("商品详情（收藏）：{}", userBehaviorDTO);
        userBehaviorService.addViews(userBehaviorDTO);
        return Result.success();
    }*/
    public Result<PageResult>starsDetail(@RequestBody ShopPageQueryDTO shopPageQueryDTO) {
        log.info("商品收藏记录信息查询：{}", shopPageQueryDTO);
        PageResult page = userBehaviorService.list(shopPageQueryDTO);
        return Result.success(page);
    }
}
